package com.pureland.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.AuthenticationEntryPoint;


/**
 * @projectName: pureland_cloud
 * @className: com.pureland.security.Oauth2AutoConfiguration
 * @description: OAuth2自动配置类
 * @author: tong.li
 * @createTime: 2020/10/12 11:04
 * @version: v1.0
 * @copyright: 版权所有 李彤 © 2020
 */
@Configuration
@ConditionalOnWebApplication
@AllArgsConstructor
@ConditionalOnProperty(prefix  = "pureland.security", value = "enabled",  matchIfMissing = true)
@ComponentScan
@EnableWebSecurity
public class Oauth2AutoConfiguration extends ClientIgnoreSecurityConfiguration {

    @Autowired
    private ObjectMapper objectMapper;

    @Bean
    public AuthenticationEntryPoint authenticationEntryPoint() {
        return new ResourceAuthExceptionEntryPoint(objectMapper);
    }



}
